#include <bits/stdc++.h>

using namespace std;
const int MAXNUM = 100000008;
const int MOD = 10000;
const int FILENUMS = 3;
int arr[MAXNUM] = { 0 };
int main() {
    memset(arr, 0, sizeof(arr));
    ofstream output("arr.txt");

    int maxnum = 0;
    for (int idx = 1; idx <= FILENUMS; idx++) {
        fstream inputfile(to_string(idx) + ".txt");
        int num;
        while (!inputfile.eof()) {
            inputfile >> num;
            maxnum = max(maxnum, num);
            arr[num]++;
        }
        inputfile.close();
    }
    int cnt = 0;
    int c = 0;
    for (int i = 0; i <= maxnum; i++) {
        if (arr[i]) {
            if ((++cnt) % MOD == 0) {
                cnt = 0;
                cout << i << endl;
                if ((++c) > 10) break;
            }
        }
        output << (arr[i] ? to_string(i) : " ") << " ";
    }
    cout << maxnum;
    output.close();
    // system("pause");
    return 0;
}
